package com.teamcenter.rac.massupdate.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.apache.log4j.Logger;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.views.properties.IPropertySource;

import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.util.AdapterUtil;
import com.teamcenter.rac.viewer.sorter.PropertyColumnViewerSorter;

public class MassUpdatePropertyColumnViewerSorter extends PropertyColumnViewerSorter {
	protected Object getValue(Object paramObject, String paramString, int paramInt, Viewer paramViewer) {
		if ((paramObject instanceof IPropertySource)) {
			if (paramString.equals("last_mod_date")) {
				TCComponent localTCComponent = (TCComponent) AdapterUtil.getAdapter(paramObject, TCComponent.class);
				SimpleDateFormat localSimpleDateFormat = localTCComponent.getSession().askDefaultDateFormat();
				try {
					return localSimpleDateFormat
							.parse((String) ((IPropertySource) paramObject).getPropertyValue(paramString));
				} catch (ParseException localParseException) {
					Logger.getLogger(MassUpdatePropertyColumnViewerSorter.class)
							.error(localParseException.getLocalizedMessage(), localParseException);
				}
			}
			return ((IPropertySource) paramObject).getPropertyValue(paramString);
		}
		return super.getValue(paramObject, paramString, paramInt, paramViewer);
	}
}
